﻿using System;
using System.Collections.Generic;

class t2
{
    static void Main()
    {
        Console.WriteLine("请输入下限：");
        int min = int.Parse(Console.ReadLine());

        Console.WriteLine("请输入上限：");
        int max = int.Parse(Console.ReadLine());

        if (min > max)
        {
            Console.WriteLine("下限不能大于上限！程序退出。");
            return;
        }

        List<int> primes = GetPrimesBetween(min, max);
        Console.WriteLine($"\n[{min}, {max}] 之间的素数如下：");
        PrintPrimes(primes, 10);
    }
    static List<int> GetPrimesBetween(int lower, int upper)
    {
        List<int> primes = new List<int>();
        for (int i = lower; i <= upper; i++)
        {
            if (IsPrime(i))
            {
                primes.Add(i);
            }
        }
        return primes;
    }

    static bool IsPrime(int number)
    {
        if (number < 2) return false;

        for (int i = 2; i * i <= number; i++)
        {
            if (number % i == 0) return false;
        }
        return true;
    }

    static void PrintPrimes(List<int> primes, int numbersPerLine)
    {
        for (int i = 0; i < primes.Count; i++)
        {
            Console.Write(primes[i] + "\t");
            if ((i + 1) % numbersPerLine == 0)
            {
                Console.WriteLine();
            }
        }
        if (primes.Count % numbersPerLine != 0)
        {
            Console.WriteLine();
        }
    }
}